<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>Google验证</title>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <script src="../common/header.js"></script>
    <!-- 内容主体区域 -->
    <div id="LAY_app_body">
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-header">Google验证开关</div>
                        <div class="layui-card-body" style="margin: 0 auto;width: 300px">
                            <form class="layui-form layui-form-pane" id="google_form" action="">
                                <div class="layui-form-item">
                                    <label for="google" class="layui-form-label">Google验证</label>
                                    <div class="layui-input-block">
                                        <input type="checkbox" id="google" lay-skin="switch" name="switchGoogle"
                                               value="0" lay-filter="switchGoogle" lay-text="开|关">
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'layer'], function (form, layer) {
        var $ = layui.$
        form = layui.form;
        form.render()

        service.get('mfconfig').then((response) => {
            if (response.data) {
                var data = response.data
                data.forEach((e) => {
                    if (e.id === 3) {
                        $('#google').attr('checked', e.values === '1')
                        form.render('checkbox')
                    }
                })
            } else {
                layer.msg(response.msg, {offset: '45vh', icon: 5, time: 2000});
            }
        }).catch((err) => {
            layer.msg(err.msg, {offset: '45vh', icon: 5, time: 2000});
        })

        //监听指定开关
        form.on('switch(switchGoogle)', function () {
            service.post('api/v1/sys/mfconfig', {
                id: 3,
                values: this.checked ? '1' : '0'
            }).then((response) => {
                if (response.code === 200) {
                    layer.msg('操作成功', {offset: '45vh', icon: 1, time: 2000});
                } else {
                    layer.msg(response.msg, {offset: '45vh', icon: 5, time: 2000});
                }
            }).catch((err) => {
                layer.msg(err.msg, {offset: '45vh', icon: 5, time: 2000});
            })
        });
    });
</script>
</body>
</html>
